package main

import (
	"fmt"
	"sync"
	"time"
)

type Task string

type Pool struct {
	Mu    sync.Mutex
	Tasks []*Task
}

func worker(pool *Pool) {
	for {
		if len(pool.Tasks) == 0 {
			return
		}
		pool.Mu.Lock()              // 加锁
		task := pool.Tasks[0]       // 获取任务
		pool.Tasks = pool.Tasks[1:] // 移除第0个任务
		pool.Mu.Unlock()            // 解锁
		go process(task)            // 执行任务
	}
}

func process(task *Task) {
	fmt.Println(*task)
}

func main() {
	var t1 Task = "张三"
	var t2 Task = "李四"
	var t3 Task = "王五"
	pool := &Pool{Tasks: []*Task{&t1, &t2, &t3}}
	worker(pool)
	time.Sleep(1e9)
}
